package com.weblog.model.user;

import javax.persistence.*;
import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

@Entity
@Table(name = "tb_permissions")
public class Permission implements Serializable {
    private static final long serialVersionUID=-4678816654942943999L;

    /**
     * 权限id
     */
    @Id
    private String pid;
    /**
     * 权限名
     */
    private String pname;
    /**
     * 说明
     */
    private String pdesc;


    /**
     * 多对多关系，被动的一方放弃维护权
     * mappedBy：对方中的映射名称
     */
    @ManyToMany(mappedBy = "permissions",fetch = FetchType.EAGER)
    private Set<Role> roles=new HashSet<>();

    @Override
    public String toString() {
        return "Permission{" +
                "pid='" + pid + '\'' +
                ", pname='" + pname + '\'' +
                ", pdesc='" + pdesc + '\'' +
                '}';
    }

    public Set<Role> getRoles() {
        return roles;
    }

    public void setRoles(Set<Role> roles) {
        this.roles = roles;
    }

    public String getPid() {
        return pid;
    }

    public void setPid(String pid) {
        this.pid = pid;
    }

    public String getPname() {
        return pname;
    }

    public void setPname(String pname) {
        this.pname = pname;
    }


    public String getPdesc() {
        return pdesc;
    }

    public void setPdesc(String pdesc) {
        this.pdesc = pdesc;
    }
}
